package org.movieexample.ws;

import java.util.List;

import javax.jws.WebService;

import org.movieexample.www.movie.GetAllMovieData;
import org.movieexample.www.movie.GetAllMovieDataResponse;
import org.movieexample.www.movie.GetMovieInfoByGenre;
import org.movieexample.www.movie.GetMovieInfoByGenreResponse;
import org.movieexample.www.movie.GetMovieInfoByName;
import org.movieexample.www.movie.GetMovieInfoByNameResponse;
import org.movieexample.www.movie.GetMovieInfoByTheatre;
import org.movieexample.www.movie.GetMovieInfoByTheatreResponse;
import org.movieexample.www.movie.GetMovieInfoByTime;
import org.movieexample.www.movie.GetMovieInfoByTimeResponse;
import org.movieexample.www.movie.GetMovieInfoByType;
import org.movieexample.www.movie.GetMovieInfoByTypeResponse;
import org.movieexample.www.movie.Movie;
import org.movieexample.www.movie.Movies;
import org.movieexample.www.movie.ServiceUnavailableException;

import org.movieexample.ws.GetAllMovieDataFault;
import org.movieexample.ws.GetMovieInfoByGenreFault;
import org.movieexample.ws.GetMovieInfoByNameFault;
import org.movieexample.ws.GetMovieInfoByTheatreFault;
import org.movieexample.ws.GetMovieInfoByTimeFault;
import org.movieexample.ws.GetMovieInfoByTypeFault;
import org.movieexample.ws.MovieSkeletonInterface;

public class MovieBusiness implements MovieSkeletonInterface
{

	@Override
	public GetMovieInfoByTypeResponse getMovieInfoByType(
			GetMovieInfoByType getMovieInfoByType)
			throws GetMovieInfoByTypeFault 		
	{
		Movie[] movielist;
		GetMovieInfoByTypeResponse result = new GetMovieInfoByTypeResponse();
		try 
		{
			movielist=MovieDAO.getMovieInfoByType("PG");
			Movies movies = new Movies();
			movies.setMovie(movielist);
			result.setGetMovieInfoByTypeResponse(movies);
		} 
		catch (Exception e) 
		{
			ServiceUnavailableException excep = new ServiceUnavailableException();
			excep.setServiceUnavailableException(ErrorMessages.ServiceUnavailableError);
			GetMovieInfoByTypeFault typefault = new GetMovieInfoByTypeFault();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
		return result;
	}

	@Override
	public GetMovieInfoByTheatreResponse getMovieInfoByTheatre(
			GetMovieInfoByTheatre getMovieInfoByTheatre)
			throws GetMovieInfoByTheatreFault 
	{
		Movie[] movielist;
		GetMovieInfoByTheatreResponse result = new GetMovieInfoByTheatreResponse();
		try 
		{
			movielist=MovieDAO.getMovieInfoByTheatre("");
			Movies movies = new Movies();
			movies.setMovie(movielist);
			result.setGetMovieInfoByTheatreResponse(movies);
		} 
		catch (Exception e) 
		{
			ServiceUnavailableException excep = new ServiceUnavailableException();
			excep.setServiceUnavailableException(ErrorMessages.ServiceUnavailableError);
			GetMovieInfoByTheatreFault typefault = new GetMovieInfoByTheatreFault();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
		return result;
	}

	@Override
	public GetAllMovieDataResponse getAllMovieData(
			GetAllMovieData getAllMovieData) throws GetAllMovieDataFault 
	{
		
		Movies movielist;
		GetAllMovieDataResponse result = new GetAllMovieDataResponse();
		try 
		{
			movielist=MovieDAO.getAllMovieData();
			result.setGetAllMovieDataResponse(movielist);
		} 
		catch (Exception e) 
		{
			ServiceUnavailableException excep = new ServiceUnavailableException();
			excep.setServiceUnavailableException(ErrorMessages.ServiceUnavailableError);
			GetAllMovieDataFault typefault = new GetAllMovieDataFault();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
		return result;
		
	}

	@Override
	public GetMovieInfoByGenreResponse getMovieInfoByGenre(
			GetMovieInfoByGenre getMovieInfoByGenre)
			throws GetMovieInfoByGenreFault 
	{
		Movie[] movielist;
		GetMovieInfoByGenreResponse result = new GetMovieInfoByGenreResponse();
		try 
		{
			movielist=MovieDAO.getMovieInfoByGenre("Comedy");
			Movies movies = new Movies();
			movies.setMovie(movielist);
			result.setGetMovieInfoByGenreResponse(movies);
		} 
		catch (Exception e) 
		{
			ServiceUnavailableException excep = new ServiceUnavailableException();
			excep.setServiceUnavailableException(ErrorMessages.ServiceUnavailableError);
			GetMovieInfoByGenreFault typefault = new GetMovieInfoByGenreFault();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
		return result;
	}

	@Override
	public GetMovieInfoByTimeResponse getMovieInfoByTime(
			GetMovieInfoByTime getMovieInfoByTime)
			throws GetMovieInfoByTimeFault 
	{
		Movies movielist;
		GetMovieInfoByTimeResponse result = new GetMovieInfoByTimeResponse();
		try 
		{
			movielist=MovieDAO.getMovieInfoByTime("PG");
			result.setGetMovieInfoByTimeResponse(movielist);
		} 
		catch (Exception e) 
		{
			ServiceUnavailableException excep = new ServiceUnavailableException();
			excep.setServiceUnavailableException(ErrorMessages.ServiceUnavailableError);
			GetMovieInfoByTimeFault typefault = new GetMovieInfoByTimeFault();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
		return result;
	}

	@Override
	public GetMovieInfoByNameResponse getMovieInfoByName(
			GetMovieInfoByName getMovieInfoByName)
			throws GetMovieInfoByNameFault 
	{
		Movie movie;
		GetMovieInfoByNameResponse result = new GetMovieInfoByNameResponse();
		try 
		{
			movie=MovieDAO.getMovieInfoByName("Love");
			result.setGetMovieInfoByNameResponse(movie);
		} 
		catch (Exception e) 
		{
			ServiceUnavailableException excep = new ServiceUnavailableException();
			excep.setServiceUnavailableException(ErrorMessages.ServiceUnavailableError);
			GetMovieInfoByNameFault typefault = new GetMovieInfoByNameFault();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
		return result;
	}
	
}
